package cn.imvc.app.repositories;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import cn.imvc.app.entities.AttrClass;
import cn.imvc.app.entities.GoodsAttrValue;
import cn.imvc.data.jpa.repository.IJpqlExecutor;

public interface GoodsAttrValueRepository extends JpaRepository<GoodsAttrValue, Integer>, IJpqlExecutor<GoodsAttrValue> {
	@Query("select g from GoodsAttrValue g where g.goodsId = :goodsId order by g.attrClass.sort asc")
	List<GoodsAttrValue> findByGoodsId(@Param("goodsId")int goodsId);
	
	List<GoodsAttrValue> findByGoodsIdAndAttrClass(int goodsId,AttrClass attrClass);
	
	List<GoodsAttrValue> findByGoodsIdAndAttrClassAndAttrValueName(int goodsId,AttrClass attrClass,String attrValueName);
	
	@Query("select g from GoodsAttrValue g where g.goodsId in (select gt.id from Goods gt where gt.goodsClass.id = :gcid) and g.attrClass = :attrClass")
	List<GoodsAttrValue> findByGoodsClass(@Param("gcid")int goodsClassId,@Param("attrClass")AttrClass attrClass);
}
